﻿
namespace MadLibrary.Math
{
    /// <summary>
    /// Holds direct proportionality informations and calculates data.
    /// </summary>
    public class DirectProportionality
    {
        /// <summary>
        /// Gets or sets coeffictient of current proportionality.
        /// </summary>
        public double Coefficient { get; set; }

        /// <summary>
        /// Creates new DirectProportionality and sets coefficient to zero.
        /// </summary>
        public DirectProportionality()
        {
            this.Coefficient = 0.0;
        }

        /// <summary>
        /// Creates new direct proportionality and sets coefficient to specified value.
        /// </summary>
        /// <param name="Coeffictient">Specifies coefficient value for new proportionality.</param>
        public DirectProportionality(double Coeffictient)
        {
            this.Coefficient = Coeffictient;
        }

        /// <summary>
        /// Gets Y value from current direct proportionality.
        /// </summary>
        /// <param name="x">Specifies X value for Y value calculation.</param>
        /// <returns>Y value of current proportionality.</returns>
        public double GetY(double x)
        {
            return this.Coefficient * x;
        }
        
        /// <summary>
        /// Gets X value from current direct proportionality.
        /// </summary>
        /// <param name="y">Specifies Y value for X value calculation.</param>
        /// <returns>Y value of current proportionality.</returns>
        public double GetX(double y)
        {
            return y / this.Coefficient;
        }

        /// <summary>
        /// Calculates coefficient from specified data.
        /// </summary>
        /// <param name="x">Specifies X value for coefficient calculation.</param>
        /// <param name="y">Specifies Y value for coefficient calculation.</param>
        public void SetCoefficient(double x, double y)
        {
            this.Coefficient = y / x;
        }

        /// <summary>
        /// Calculates coefficient from specified data.
        /// </summary>
        /// <param name="x">Specifies X value for coefficient calculation.</param>
        /// <param name="y">Specifies Y value for coefficient calculation.</param>
        /// <returns>Calculated coefficient.</returns>
        public static double GetCoefficient(double x, double y)
        {
            return y / x;
        }

        /// <summary>
        /// Calculates X value from specified data.
        /// </summary>
        /// <param name="coefficient">Specifies coefficient for X value calculation.</param>
        /// <param name="y">Specifies Y value for X value calculation.</param>
        /// <returns>Calculated X value.</returns>
        public static double GetX(double coefficient, double y)
        {
            return y / coefficient;
        }

        /// <summary>
        /// Calculates Y value from specified data.
        /// </summary>
        /// <param name="coefficient">Specifies coefficient for Y value calculation.</param>
        /// <param name="x">Specifies X value for Y value calculation.</param>
        /// <returns>Calculated Y value.</returns>
        public static double GetY(double coefficient, double x)
        {
            return coefficient * x;
        }
    }
}